package cn.shengongying.admin.controller;

import cn.shengongying.admin.dto.BossOrderInDTO;
import cn.shengongying.bean.DataTablePageResult;
import cn.shengongying.bean.ResponseResult;
import cn.shengongying.model.BossOrder;
import cn.shengongying.service.IBossOrderService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * author: RXK
 * date: 2022/2/11 星期五
 * desc:
 */
@Controller
@RequestMapping("/sys/invoice")
public class InvoiceController extends BaseController {

    private final IBossOrderService bossOrderService;

    public InvoiceController(IBossOrderService bossOrderService) {
        this.bossOrderService = bossOrderService;
    }


    @RequestMapping("/index")
    public String index() {
        return "/invoice/index";
    }


    @ResponseBody
    @RequestMapping("/list")
    public DataTablePageResult<List<BossOrder>> list(@RequestBody BossOrderInDTO inDTO) {
        List<BossOrder> bossOrderList = bossOrderService.findInvoiceList(inDTO.getStart(), inDTO.getLength());
        inDTO.setData(bossOrderList);
        long count = bossOrderService.countInvoice();
        inDTO.setRecordsTotal(count);
        return inDTO;
    }


    @ResponseBody
    @RequestMapping("/update/status")
    public ResponseResult<String> updateInvoiceStatus(@RequestBody BossOrderInDTO inDTO) {
        BossOrder bossOrder = new BossOrder();
        bossOrder.setId(inDTO.getId());
        bossOrder.setInvoiceStatus(3);
        bossOrderService.updateById(bossOrder);
        return ResponseResult.success();
    }

}
